cp2023_ag6

  • Home
    • SMap
    • reveal
    • blog
  • About
  • INFO
  • mass-spring-damper
  • Euler Method
  • replit
    • step1
    • step2
    • step3
    • step4
    • 補充
  • gd
  • work
    • 台灣國旗
    • 美國國旗
    • 日本國旗
    • 中國國旗
    • 英國國旗
    • 韓國國旗
  • test
    • w15_test
    • exam_test
      • 錯的題目
  • 倉儲及網站評分
  • 個人學習心得
  • file
  • Brython
mass-spring-damper << Previous Next >> replit

Euler Method

參考來源:歐拉方法

數值分析相關資料:

歐拉法(Euler's Method)是一種用於數值解常微分方程(ODEs)的基本數值分析方法。該方法由Leonhard Euler提出,被廣泛應用於解析度較差的情況下的ODEs,尤其是當找不到解析解時。

歐拉法的基本思想:

  1. 離散化: 將自變量(通常是時間)劃分成小的步長。
  2. 近似: 使用當前的微分值(斜率)來估計下一個時間步長的函數值。

def euler_method(f, y0, t0, tn, h):
    """
    使用歐拉法進行數值積分

    Parameters:
    - f: 函數 f(t, y) 表示 ODE 的右側
    - y0: 初值
    - t0: 初始時間
    - tn: 終止時間
    - h: 步長

    Returns:
    - t_values: 時間值的列表
    - y_values: 對應的函數值列表
    """
    t_values = [t0]
    y_values = [y0]
    t = t0
    y = y0

    while t < tn:
        y = y + h * f(t, y)
        t = t + h
        t_values.append(t)
        y_values.append(y)

    return t_values, y_values

mass-spring-damper << Previous Next >> replit

Copyright © All rights reserved | This template is made with by Colorlib